﻿using System;
using gms.data;
using gms.system;

namespace gms.page.admin {
	public partial class playermgr_del : GMSPage {
		public bool posted = false;
		public Player player;

		public playermgr_del() : base() {
			this.Load += new EventHandler(playermgr_del_Load);
		}

		void playermgr_del_Load(object sender, EventArgs e) {
			int player_id = 0;

			if (Request.QueryString.Count != 0) {
				if (Request.QueryString["id"].Length != 0) {
					if (!int.TryParse(Request.QueryString["id"], out player_id)) {
						Response.Redirect("playermgr.aspx");
					}
				}
				else {
					Response.Redirect("playermgr.aspx");
				}
			}
			else {
				Response.Redirect("playermgr.aspx");
			}

			if (player_id == 1) {
				Response.Redirect("playermgr.aspx");
			}

			if (Request.Form.Count != 0) {
				posted = true;
			}

			player = nhdb.session.Get<Player>(player_id);

			if (player == null) {
				Response.Redirect("playermgr.aspx");
			}

			if (posted) {
				nhdb.session.BeginTransaction();
				nhdb.session.Delete(player);
				nhdb.session.Transaction.Commit();

				Response.Redirect("playermgr.aspx");
			}
		}
	}
}